package com.ztsoft.user.service.project.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ztsoft.user.mapper.project.ExpendMapper;
import com.ztsoft.user.mapper.project.SupplierMapper;
import com.ztsoft.user.pojo.entity.project.PExpend;
import com.ztsoft.user.pojo.entity.project.Supplier;
import com.ztsoft.user.pojo.page.PageQuery;
import com.ztsoft.user.service.project.ExpendService;
import com.ztsoft.user.service.project.SupplierService;
import com.ztsoft.user.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author 12487
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
    @Resource
    public SupplierMapper supplierMapper;

    @Override
    public Result<Object> list(Supplier bo, PageQuery pageQuery) {
        QueryWrapper<Supplier> lqw =new QueryWrapper();
        lqw.like(ObjectUtil.isNotEmpty(bo.getSupplierName()),"supplier_name",bo.getSupplierName());
        lqw.like(ObjectUtil.isNotEmpty(bo.getOpenBank()),"supplier_name",bo.getOpenBank());
        lqw.like(ObjectUtil.isNotEmpty(bo.getLinkman()),"linkman",bo.getLinkman());
        lqw.like(ObjectUtil.isNotEmpty(bo.getTaxId()),"tax_id",bo.getTaxId());
        lqw.like(ObjectUtil.isNotEmpty(bo.getPhone()),"phone",bo.getPhone());
        Page<Supplier> result = supplierMapper.selectPage(pageQuery.build(),lqw);
        return Result.success(result);
    }

    @Override
    public Result<Object> expendOne(String id) {
        return Result.success(supplierMapper.selectById(id));
    }

    @Override
    public Result<Object> add(Supplier bo) {
        return Result.success(supplierMapper.insert(bo));
    }
    @Override
    public Result<Object> update(Supplier bo) {
        return Result.success(supplierMapper.updateById(bo));
    }
    @Override
    public Result<Object> delete(String[] ids) {
        return Result.success(supplierMapper.deleteBatchIds(Arrays.asList(ids)));
    }


}
